//
//  RankTableViewCell.m
//  sklive
//
//  Created by Macx on 2017/6/28.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "RankTableViewCell.h"
#import "User.h"

@implementation RankTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backgroundColor = kWhiteColor;
    
    self.rank.font = kUHSystemFontWithSize(16);
    self.rank.frame = CGRectMake(10, 10, SW(8)-20, SW(8));
    
    self.headPic.frame = CGRectMake(SW(8), 10, SW(8), SW(8));
    self.headPic.layer.cornerRadius = SW(16);
    self.headPic.layer.masksToBounds = YES;
    
    self.level.frame = CGRectMake(self.headPic.x+self.headPic.width/3*2, self.headPic.y+self.headPic.height/3*2, self.headPic.width/3, self.headPic.width/3);
    
    CGSize nickNameSize = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(14)];
    CGSize signSize = [LZCTools textSizeWithText:@"字数" font:kUHSystemFontWithSize(12)];
    
    self.nickName.font = kUHSystemFontWithSize(14);
    self.nickName.frame = CGRectMake(self.headPic.x+SW(8)+10, 10, SCREEN_WIDTH-self.nickName.x-10, nickNameSize.height);
  
    self.praiseNum.font = kUHSystemFontWithSize(12);
    self.praiseNum.frame = CGRectMake(self.nickName.x, 10+SW(8)-signSize.height, SCREEN_WIDTH/2, signSize.height);
    
//    self.optionsBtn.frame = CGRectMake(SCREEN_WIDTH-10-nickNameSize.width*2-10, 10+SW(14)-nickNameSize.height/2-2, nickNameSize.width*2+10, nickNameSize.height+4);
//    [self.optionsBtn setTitle:@"+ 关注" forState:UIControlStateNormal];
//    self.optionsBtn.titleLabel.font = kUHSystemFontWithSize(13);
//    self.optionsBtn.layer.cornerRadius = self.optionsBtn.bounds.size.height/2;
//    self.optionsBtn.layer.borderWidth = 1;
//    self.optionsBtn.layer.borderColor = RGB(244, 124, 153).CGColor;
//    self.optionsBtn.layer.masksToBounds = YES;

    self.optionsBtn.titleLabel.font = kUHSystemFontWithSize(13);
    [self.optionsBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
    CGSize size3 = [LZCTools textSizeWithText:@"未关注" font:kUHSystemFontWithSize(13)];
    CGFloat focusWidth = self.headPic.height/2+5+size3.width;
    self.optionsBtn.frame = CGRectMake(SCREEN_WIDTH-10-focusWidth, self.headPic.height/4+10, focusWidth, self.headPic.height/2);
    
}


- (void)setModel:(User *)model {
    
    if (_model != model) {
        _model = model;
        
        [self.headPic sd_setImageWithURL:[NSURL URLWithString:model.face] placeholderImage:IMAGE(@"placeHolder")];
        
        self.nickName.text = model.nickname;
        
        if ([[GetUserDefaule(USERINFO) valueForKey:@"user_id"] isEqualToString:[NSString stringWithFormat:@"%@", [model valueForKey:@"user_id"]]]) {
            self.optionsBtn.hidden = YES;
        }
        else
            self.optionsBtn.hidden = NO;
        
        if ([[model valueForKey:@"is_like"] intValue] == 1) {
            [self.optionsBtn setBackgroundImage:IMAGE(@"btn_concerned_bg") forState:UIControlStateNormal];
            [self.optionsBtn setImage:[IMAGE(@"btn_ed_concern") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            [self.optionsBtn setTitle:@"已关注" forState:UIControlStateNormal];
        }
        else {
            [self.optionsBtn setBackgroundImage:IMAGE(@"btn_unconcern_bg") forState:UIControlStateNormal];
            [self.optionsBtn setImage:[IMAGE(@"btn_un_concern") imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
            [self.optionsBtn setTitle:@"  关注" forState:UIControlStateNormal];
        }
//        self.praiseNum.text = [NSString stringWithFormat:@"星光值:%ld", model.star_rank];
        
        if (model.role == 1) {
            self.level.image = IMAGE(@"");
        }
        else if (model.role == 3 || model.role == 4 || model.role == 6) {
            self.level.image = IMAGE(@"icon_add_v");
        }
        
        if (model.star_rank > 0) {
            self.praiseNum.text = [NSString stringWithFormat:@"星光值:%ld", model.star_rank];
        }
        else if (model.contribution_rank > 0) {
            self.praiseNum.text = [NSString stringWithFormat:@"贡献值:%ld", model.contribution_rank];
        }
        else if (model.followers_count > 0) {
            self.praiseNum.text = [NSString stringWithFormat:@"粉丝数:%ld", model.followers_count];
        }
    }
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
